package com.analysis.server.model;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;

@Data
@TableName("log_template") // 表名映射
public class LogTemplate {

    @TableId(value = "id", type = IdType.AUTO) // 主键映射
    private Long id;

    @TableField("name")
    private String name;

    @TableField("description")
    private String description;

    @TableField("preparing_format")
    private String preparingFormat; // Preparing 行模板

    @TableField("preparing_regex")
    private String preparingRegex; // Preparing 行正则表达式

    @TableField("parameters_format")
    private String parametersFormat; // Parameters 行模板

    @TableField("parameters_regex")
    private String parametersRegex; // Parameters 行正则表达式

    @TableField("total_format")
    private String totalFormat; // Total/Row 行模板

    @TableField("total_regex")
    private String totalRegex; // Total/Row 行正则表达式

    @TableField("thread_matching_strategy")
    private String threadMatchingStrategy; // 线程匹配策略: "exact", "prefix", "contains"

    @TableField("sql_timeout_threshold")
    private Long sqlTimeoutThreshold; // SQL超时阈值(毫秒)，默认30000

    @TableField("enabled")
    private Boolean enabled; // 是否启用

    @TableField("create_time")
    private java.time.LocalDateTime createTime;

    @TableField("update_time")
    private java.time.LocalDateTime updateTime;



    public LogTemplate() {
        this.enabled = true;
        this.sqlTimeoutThreshold = 30000L;
        this.threadMatchingStrategy = "exact";
        this.createTime = java.time.LocalDateTime.now();
        this.updateTime = java.time.LocalDateTime.now();
    }

    // 获取超时阈值，如果未设置则使用默认值
    public Long getSqlTimeoutThreshold() {
        return sqlTimeoutThreshold != null ? sqlTimeoutThreshold : 30000L;
    }

    // 获取线程匹配策略，如果未设置则使用默认值
    public String getThreadMatchingStrategy() {
        return threadMatchingStrategy != null ? threadMatchingStrategy : "exact";
    }

    // 检查是否启用
    public Boolean getEnabled() {
        return enabled != null ? enabled : true;
    }
}